home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / fractal / fcloud.arc / gauss_sup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-05  |  768 b   |  32 lines

  1. #include <exec/types.h>
  2. #include <limits.h>
  3. #include <math.h>
  4.  
  5. #define Arand INT_MAX    /* rand() returns values between 0 and Arand */
  6.  
  7. SHORT Nrand;            /* the # of samples of rand() to be taken in Gauss() */
  8. double GaussAdd;            /* real parameter for linear transformation in Gauss() */
  9. double GaussFac;            /* ditto */
  10.  
  11. /* InitGauss() will initialize the Random Gauss routine */
  12. void InitGauss(seed)
  13. unsigned int seed;
  14. {
  15.     Nrand = 4;
  16.     GaussAdd = sqrt((double)(3.0 * Nrand));
  17.     GaussFac = (double)2.0 * GaussAdd / ((double)Nrand * (double)Arand);
  18.     srand((unsigned)seed);
  19. }
  20.  
  21. /* Gauss() will return a Gaussian random number */
  22. double Gauss(void)
  23. {
  24.     double sum,c;
  25.     SHORT i;
  26.  
  27.     sum = 0.0;
  28.     for(i=0;i<Nrand;i++) 
  29.         sum += (double)rand();
  30.     c = GaussFac * sum - GaussAdd;
  31.     return(c);
  32. }